< previous page page_96 next page >

Page 96
cal color &HD0FFD1 in entry 245. Because the inverted value for 10 is 245, lines drawn in invert mode over either of these colors will be very difficult to see. In fact, these colors are so similar that your screen may display them identically or your eyes may not be able to tell the difference. Whether inverted non-static colors provide a good contrast depends on the colors in the system palette and the order in which they are loaded.
Colors in Visual Basic
There are several ways you can specify a color in Visual Basic. One of the best methods is to use a constant such as vbCyan. These colors are part of the static colors, so they should always be available, and using constants with meaningful names makes your code easier to understand.
You can also use the RGB function to calculate the value of a color based on its component values. If a pixel's color components are R, G, and B, then:
e10a6a0a59f035e870d90cca05b85fce.gif
RGB(R, G, B) = R + G * 256 + B * 256 * 256
For instance, RGB(&HFF, &HFF, &H00) = &H00FFFF, which is yellow.
When you specify a color using these sorts of RGB values, Visual Basic matches the color to the closest one available in the current logical palette. This may not always be a very close match to the color you want.
If your program executes a command that fills an area, Visual Basic tries to fill the area with a color in the logical palette. If the picture box uses the default Visual Basic palette, only the system static colors are available. If there is no exact match for the color your program specifies, the system uses a combination of two static colors in a pattern to approximate that color. Using this type of color patterning to approximate another color is called dithering.
For example, suppose a program executes the following command.
e10a6a0a59f035e870d90cca05b85fce.gif
Line (0, 0)-(50, 50), RGB(255, 127, 127), BF
Visual Basic tries to draw a box filled with the color salmon pink. Because pink is not a static color, the system approximates pink by filling the box with red covered by a pattern of white dots. Over a large area, this gives a reasonable approximation of the color pink.
By using only static colors, Visual Basic increases the chances that your program can find the colors it needs and that the display will look the same no matter what foreground palette is currently realized. On the other hand, Visual Basic does not use the exact colors your program requests unless you happen to use only static colors.
Example program Rainbow demonstrates the difference between Visual Basic's default color behavior and the use of a palette. Use the scrollbars to set the red, green, and blue color components for the color you want to see.
The picture box on the left uses Visual Basic's default, static colors. The program fills this box using the RGB function so colors are dithered to approximate the color you specify.

 
< previous page page_96 next page >